package com.cb.spzx.common.exception;

import com.cb.spzx.model.vo.common.Result;
import com.cb.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    //全局异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(){
        return Result.build(null, ResultCodeEnum.DATA_ERROR);
    }

    //自定义异常处理
    @ExceptionHandler(CbException.class)
    @ResponseBody
    public Result error(CbException e){
        return Result.build(null, e.getResultCodeEnum());
    }

}

